# 【需求02】有十名学生【“王一”，“胡二"，“张三"，“李四"，“赵五"，
# “马六"，“杨七”，“刘八”，“孙九"，“陈十”】，
# 每个学生有五门科目【语文、数学、英语、物理、化学】，
# 为这5位同学随机生成5门考试的成绩【成绩介于50-100间】
# 要求：输出第一名和最后一名学生的姓名、总分、均分以及每门科目的成绩

from random import randint


class Student:
    def __init__(self):
        self.student_list = [
            "王一", "胡二", "张三", "李四", "赵五", "马六", "杨七", "刘八", "孙九", "陈十"
        ]
        self.msg_list = []
        self.crouse_list = ["语文", "数学", "英语", "物理", "化学"]
        self.first_student = 0
        self.last_student = 0

    def gen_score(self):

        for i in range(len(self.student_list)):
            score_list = []
            temp_total = 0
            score_list.append(self.student_list[i])
            for j in range(1, len(self.crouse_list) + 1):
                temp_score = randint(50, 100)
                score_list.append(temp_score)
                temp_total += temp_score
            temp_averg = temp_total / len(self.crouse_list)
            score_list.append(temp_total)
            score_list.append(temp_averg)
            self.msg_list.append(score_list)

    def compare(self):
        first_student_score = self.msg_list[0][-2]
        last_student_score = self.msg_list[0][-2]
        self.first_student = 0
        self.last_student = 0
        for i in range(1, len(self.student_list)):
            if self.msg_list[i][-2] > first_student_score:
                self.first_student = i
            elif self.msg_list[i][-2] < last_student_score:
                self.last_student = i

    def main(self):
        self.gen_score()
        self.compare()
        first_msg = self.msg_list[self.first_student]
        last_msg = self.msg_list[self.last_student]
        print("成绩第一名的是{0},总分：{6}，平均分：{7}，语文：{1}，数学：{2}，英语：{3}，物理：{4}，化学：{5}".
              format(*first_msg))
        print("成绩最后一名是{0},总分：{6}，平均分：{7}，语文：{1}，数学：{2}，英语：{3}，物理：{4}，化学：{5}".
              format(*last_msg))


if __name__ == "__main__":
    this_project = Student()
    this_project.main()